//
//  SCNFinancialPlannerHeaderView.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/9/12.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNFinancialPlannerHeaderView: UIView {
    
    var friendListClosures: (() -> Void)?
    
    
    lazy var topView: UIView = {
        let view = UIView()
        view.backgroundColor = SCNConstants.colorWith255RGBA(230, g: 230, b: 230, a: 1)
        return view
    }()
    lazy var headImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named:"account_placeholder_head"))
        imgView.layer.cornerRadius = 30
        imgView.layer.borderWidth = 1.5
        imgView.layer.borderColor = UIColor.lightGray.cgColor
        return imgView
    }()
    lazy var nameL: UILabel = {
        let lab = UILabel()
        lab.textColor = SCNConstants.colorWith255RGBA(36, g: 36, b: 36, a: 1)
        lab.font = UIFont.systemFont(ofSize: 14.0)
        lab.text = "王大哥"
        return lab
    }()
    lazy var detailL: UILabel = {
        let lab = UILabel()
        lab.textColor = SCNConstants.colorWith255RGBA(136, g: 136, b: 136, a: 1)
        lab.font = UIFont.systemFont(ofSize: 14.5)
        lab.text = "您的邀请码：0000"
        return lab
    }()
    lazy var friendBtn: UIButton = {
        let btn = UIButton()
        btn.setTitle("邀请列表", for: .normal)
        btn.backgroundColor = SCNConstants.colorWith255RGBA(122, g: 197, b: 79, a: 1)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15.0)
        btn.setTitleColor(.white, for: .normal)
        btn.addTarget(self, action: #selector(friendListAction(_:)), for: .touchUpInside)
        btn.layer.cornerRadius = 15.0
        return btn
    }()
    lazy var friendImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named:"hy-icon"))
        return imgView
    }()
    lazy var moneyImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named:"jl-icon"))
        return imgView
    }()
    lazy var friendL: UILabel = {
        let lab = UILabel()
        lab.textColor = SCNConstants.colorWith255RGBA(136, g: 136, b: 136, a: 1)
        lab.font = UIFont.systemFont(ofSize: 14.5)
        lab.textAlignment = .center
        lab.text = "您已邀请好友0位"
        return lab
    }()
    lazy var moneyL: UILabel = {
        let lab = UILabel()
        lab.textColor = SCNConstants.colorWith255RGBA(136, g: 136, b: 136, a: 1)
        lab.font = UIFont.systemFont(ofSize: 14.5)
        lab.text = "累计获得奖励0元"
        lab.textAlignment = .center
        return lab
    }()
    lazy var bottomLine: UIView = {
        let view = UIView()
        view.backgroundColor = SCNConstants.tableViewBackgroundColor
        return view
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
        addSubview(topView)
        topView.addSubview(headImgView)
        topView.addSubview(nameL)
        topView.addSubview(detailL)
        topView.addSubview(friendBtn)
        addSubview(friendImgView)
        addSubview(moneyImgView)
        addSubview(friendL)
        addSubview(moneyL)
        addSubview(bottomLine)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        topView.snp.makeConstraints { (make) in
            make.top.leading.trailing.equalToSuperview()
            make.height.equalTo(80)
        }
        headImgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 60, height: 60))
            make.top.equalTo(10)
            make.leading.equalTo(15)
        }
        nameL.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 200, height: 20))
            make.top.equalTo(20)
            make.leading.equalTo(85)
        }
        detailL.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 200, height: 20))
            make.top.equalTo(45)
            make.leading.equalTo(85)
        }
        friendBtn.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 90, height: 30))
            make.trailing.equalTo(-20)
        }
        friendL.snp.makeConstraints { (make) in
            make.leading.equalToSuperview()
            make.top.equalTo(180)
            make.size.equalTo(CGSize(width: frame.size.width/2, height: 25))
        }
        moneyL.snp.makeConstraints { (make) in
            make.trailing.equalToSuperview()
            make.top.equalTo(180)
            make.size.equalTo(CGSize(width: frame.size.width/2, height: 25))
        }
        friendImgView.snp.makeConstraints { (make) in
            make.centerX.equalTo(friendL.snp.centerX)
            make.top.equalTo(100)
            make.size.equalTo(CGSize(width: 70, height: 70))
        }
        moneyImgView.snp.makeConstraints { (make) in
            make.centerX.equalTo(moneyL.snp.centerX)
            make.top.equalTo(100)
            make.size.equalTo(CGSize(width: 70, height: 70))
        }
        bottomLine.snp.makeConstraints { (make) in
            make.leading.trailing.bottom.equalToSuperview()
            make.height.equalTo(5)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // Action
    
    func friendListAction(_ sender: UIButton) {
        friendListClosures?()
    }

}
